//
//  TableViewTwoCell.m
//  lx
//
//  Created by 李响 on 15/6/9.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "TableViewTwoCell.h"
#import "CollectionViewOneCell.h"
#import "SpecialPageViewController.h"
#import "YRSideViewController.h"
#import "MyRadioViewController.h"
@interface TableViewTwoCell ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, retain) UICollectionView *collectionView;
@property (nonatomic, retain) NSMutableArray *strOne;
@property (nonatomic, retain) NSMutableArray *strTwo;
@property (nonatomic, retain) NSMutableArray *lastArrayN;
@property (nonatomic, retain) NSMutableArray *lastArrayM;

@property (nonatomic, retain) NSMutableDictionary *dicM;
@end
@implementation TableViewTwoCell
- (void)dealloc
{
    [_collectionView release];
    [_lastArrayN release];
    [_lastArrayM release];
    [_dicM release];
    [_array release];
    [_arrayOfDic release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
#warning 初始化
    self.lastArrayN = [NSMutableArray array];
    self.lastArrayM = [NSMutableArray array];
    self.dicM = [NSMutableDictionary dictionary];
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
//        //数组初始化
//        self.array = [NSArray array];
        
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        //规定每个cell大小
        flowLayout.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width * 7 / 25, [UIScreen mainScreen].bounds.size.height * 13 / 85);
        //一个section距离边缘上左下右的距离
        flowLayout.sectionInset = UIEdgeInsetsMake([UIScreen mainScreen].bounds.size.width / 25, [UIScreen mainScreen].bounds.size.width / 25, [UIScreen mainScreen].bounds.size.width / 25, [UIScreen mainScreen].bounds.size.width / 25);
        
        //在一行里面.item之间的最小间距;
        flowLayout.minimumLineSpacing = [UIScreen mainScreen].bounds.size.height / 13;
        //行之间的间距*(行;是垂直于滚动方向的叫行)
        //flowLayout.minimumInteritemSpacing = 20;
        
        self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height / 2) collectionViewLayout:flowLayout];
        //self.collectionView = [[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:flowlayout];
        
        self.collectionView.backgroundColor = [UIColor colorWithRed:0.88 green:0.90 blue:0.738 alpha:0.4];
        
        [self.collectionView registerClass:[CollectionViewOneCell class] forCellWithReuseIdentifier:@"collectionCell"];
        
        [self.contentView addSubview:self.collectionView];
        
        [_collectionView release];
        [flowLayout release];
    }
    return self;
    
}

- (void)setArray:(NSArray *)array
{
    if (_array != array) {
        [_array release];
        _array = [array retain];
    }
    [self.collectionView reloadData];
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.array.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CollectionViewOneCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionCell" forIndexPath:indexPath];
    
    cell.main = [self.array objectAtIndex:indexPath.row];
    
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

{
    for (NSMutableDictionary *tempDic in self.arrayOfDic) {
        NSMutableArray *strOne = [[[[tempDic objectForKey:@"audioList"] firstObject] objectForKey:@"audioInfo"] objectForKey:@"audioName"];
        NSMutableArray *strTwo = [[[[tempDic objectForKey:@"audioList"] firstObject] objectForKey:@"audioInfo"] objectForKey:@"mp3PlayUrl"];
        //self.dicM = [[[tempDic objectForKey:@"audioList"] firstObject] objectForKey:@"audioInfo"];
        [self.lastArrayN addObject:strOne];
        [self.lastArrayM addObject:strTwo];
    }
    
    MyRadioViewController *specialVC = [MyRadioViewController shareInstance];
    
    [specialVC.audioStream stop];
    
    specialVC.rname = [self.lastArrayN objectAtIndex:indexPath.row];
    
    specialVC.mp3Url = [self.lastArrayM objectAtIndex:indexPath.row];
    
    specialVC.playImage = [[self.arrayOfDic objectAtIndex:indexPath.item] objectForKey:@"pic"];
    
    //specialVC.mp3Url = [self.dicM  objectForKey:@"mp3PlayUrl"];
    
    YRSideViewController *YRS = (YRSideViewController *)self.window.rootViewController;
    UITabBarController *tabVC = (UITabBarController *)YRS.rootViewController;
    UINavigationController *navVC = tabVC.viewControllers[1];
    [navVC pushViewController:specialVC animated:YES];
    
    //UITabBarController *tabVC = (UITabBarController *)self.window.rootViewController;
    //UINavigationController *navVC = tabVC.viewControllers[1];
    //[navVC pushViewController:specialVC animated:YES];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
